<?php

namespace app\api\controller\v1;

use app\common\controller\Api;
use app\common\model\Banner as BannerModel;
/**
 * 接口
 */
class Banner extends Api
{
    protected $noNeedLogin = ['index'];
    protected $noNeedRight = [''];
    
    /**
     * [_initialize 初始化]
     * @return [type] [description]
     */
    public function _initialize()
    {
        parent::_initialize();
    }
     public function index($id=0)
    {
        $arr = BannerModel::where(['status' => 1])->where('group_id',$id)->with('Bannergroup')->field('id,status,starttime,endtime,createtime,updatetime',true)->where('endtime', '> time', time())->where('starttime','< time',time())->order('weigh DESC')->select();
        if($arr){
            $arr = collection($arr)->toArray();
            array_walk($arr, function(&$t) {
                unset($t['group_id']);
              });
        }
        $this->success('',$arr);
    }
}